package com.example.chatchatbackend.Controller.sendJob;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.send.SendMessage;
import com.example.chatchatbackend.entity.vo.response.SendMessageVO;
import com.example.chatchatbackend.service.sendJob.SendMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */

@Slf4j
@RestController
@RequestMapping("/api/sendMessage")
public class SendMessageController {

    @Autowired
    private SendMessageService sendMessageService;

    @GetMapping
    public RestBean<List<SendMessageVO>> getAll(){
        return RestBean.success(sendMessageService.getAll());
    }

    @PostMapping
    public RestBean<SendMessageVO> insertSendMessage(@RequestBody SendMessageVO SendMessageVO){
        SendMessageVO insertSendMessageVO = sendMessageService.insertSendMessage(SendMessageVO);
        log.info("insert--SendMessage:{}",insertSendMessageVO);
        return RestBean.success(insertSendMessageVO);

    }


    @PostMapping("/list")
    public RestBean<List<SendMessageVO>> insertSendMessageList (@RequestBody List<SendMessageVO> sendMessages){
        List<SendMessageVO> sendMessageList = sendMessageService.insertSendMessageList(sendMessages);
        log.info("insert--SendMessageList:{}",sendMessageList);
        return RestBean.success(sendMessageList);
    }


    @GetMapping("/pageThree")
    public RestBean<IPage<SendMessage>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(sendMessageService.pageThree(pageNum, pageSize));
    }

    @PutMapping
    public RestBean<SendMessageVO> updateSendMessage(@RequestBody SendMessageVO sendMessageVO){
        return RestBean.success(sendMessageService.updateSendMessage(sendMessageVO));

    }

    @DeleteMapping("/ids")
    public RestBean<String> deleteByIds(@RequestBody List<Integer> ids) {
        sendMessageService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }

    @GetMapping("/ids")
    public RestBean<List<SendMessageVO>> findByIds(@RequestBody List<Integer> ids){
        List<SendMessageVO> sendMessageVOList = sendMessageService.findByIds(ids);
        return RestBean.success(sendMessageVOList);
    }


}
